<template>
  <view>
    <custom-navbar title="通过初筛" :autoBack="true" leftIconColor="#303133" />
    <view
      class="drop-down mb-30rpx h-88rpx flex items-center justify-between bg-#fff px-74rpx text-28rpx"
    >
      <view
        v-for="item in menu"
        :key="item.type"
        class="flex items-center"
        @tap="showPopup(item)"
      >
      {{item.name}}
        <up-icon color="#4e5969" size="16rpx" name="arrow-down-fill" />
      </view>
    </view>
    <view>
      <view v-for="item, key in res" :key="key" class="mb-32rpx bg-#fff px-54rpx">
        <view class="flex items-center justify-between px-0rpx py-24rpx bg-#f7f9ff text-[#1d2129] text-[26rpx]"
        v-if="item.have_teacher == 1">
          <text>{{item.teacher_school_name}}·{{item.teacher_college_name}}·{{item.teacher_name}}老师推荐 </text>
          <text>{{item.status_name}}</text>
        </view>
      <view class="pb-36rpx pt-18rpx">
        <view @click="routerToResumeDetail(item.resume_id)">
          <up-gap height="20rpx" />
          <view class="flex">
            <view class="mr-16rpx h-100rpx w-100rpx shrink-0">
              <up-image width="100rpx" height="100rpx" shape="circle"
              :src="item.avatar"/>
            </view>
            <view class="flex-auto">
              <view class="mb-16rpx flex items-center justify-between">
                <view class="text-32rpx color-#1d2129">
                  {{item.name}}
                </view>

              </view>
              <view class="flex text-26rpx color-#6e6d72 leading-100%">
                <text>{{item.province}}·{{item.city}}</text>
                <up-line length="30rpx" color="#6e6d72" direction="col" margin="0 12rpx" />
                <text>{{item.gender}}</text>
                <up-line length="30rpx" color="#6e6d72" direction="col" margin="0 12rpx" />
                <text>{{item.qualification}}</text>
                <up-line length="30rpx" color="#6e6d72" direction="col" margin="0 12rpx" />
                <text>{{item.nature}}</text>
              </view>
            </view>
          </view>
          <up-gap height="20rpx" />
          <view class="flex flex-wrap gap-10rpx justify-between">
            <view class="flex items-center">
              <view class="mr-10rpx bg-#fcf8e9 px-8rpx color-#f57100 leading-42rpx"
                v-for="highlight in item.highlights">
                {{highlight}}
              </view>
            </view >
          </view>
          <view style="border-bottom: 1px solid #ededed;" class="mt-22rpx mb-30rpx"></view>
          <view class="flex flex-wrap items-center text-26rpx color-#6e6d72 leading-36rpx">
            <text>{{item.school_name}}</text>
            <up-line length="30rpx" color="#6e6d72" direction="col" margin="0 12rpx" />
            <text>{{item.college_name}}</text>
            <up-line length="30rpx" color="#6e6d72" direction="col" margin="0 12rpx" />
            <text>{{item.status_overseas_study}}</text>
          </view>
          <up-gap height="20rpx" />
          <view class="flex items-center justify-between">
          <view class="flex flex-wrap items-center text-26rpx color-#4e5968 leading-36rpx">
            <text>{{item.heart_content}}</text>
          </view>
        </view>
      </view>
      <view style="border-bottom: 1px solid #ededed;" class="mt-22rpx mb-30rpx"></view>
          <view class="flex items-center justify-between">
            <view class="bg-#f3f4f8 rounded-[30rpx] py-12rpx px-24rpx text-[#7b7b7b] text-[24rpx]"
            v-if="item.status==1"
            @click="onClickNoAgree(item.job_resume_id, key)">不合适</view>
            <view class="py-12rpx px-24rpx"
            v-if="item.status!=1"
            ></view>
            <view class="flex items-center">
                <view class="bg-#f3f4f8 rounded-[30rpx] py-12rpx px-24rpx text-[#7b7b7b] text-[24rpx] flex items-center mr-20rpx">
                    <view class="mr-20rpx">{{statusList[item.status]}}</view>
                    <view class="iconfont icon-xiajiantou"></view>
                </view>
                <up-button
            :custom-style="{
              width: '144rpx',
              height: '58rpx',
              background: '#1f50f2',
              'border-radius': '60rpx',
              'font-size': '24rpx',
              color: '#ffffff',
              margin: '0',
            }"
          >
            立即沟通
          </up-button>
            </view>

          </view>
      </view>
    </view>

    </view>
    <up-popup
      :show="popupData.show"
      mode="center"
      :safe-area-inset-bottom="false"
      bg-color="transparent"
      @close="close"
      @open="open"
    >
      <view class="w-662rpx overflow-hidden rounded-24rpx bg-#fff">
        <view class="relative h-106rpx flex items-center justify-end px-24rpx">
          <text
            class="absolute left-50% top-50% translate-[-50%] text-center text-[28rpx] text-[#1d2129] font-medium"
          >
            {{ popupData.title }}
          </text>
          <up-icon
            :name="PopupClose"
            color="#f2f2f2"
            size="44rpx"
            @tap="popupData.show = false"
          />
        </view>
        <view>
          <!-- 职位分类 -->
          <SecondaryCategory
            v-if="popupData.menuType === '1'"
            :type="popupData.menuType"
            :list="classificationList"
            @getSearchList="getSearchList"
          />
          <view class="text-center" v-if="popupData.menuType === '2'">
            <view class="py-24rpx" v-for="item in statusList" @click="getStatus(item)">{{item.name}}</view>
          </view>
        </view>
      </view>
    </up-popup>
  </view>
</template>

  <script setup lang="ts">
// import PopupClose from "@/static/images/common/popup-close.png";
import {hrRectiveResumeList, hrResumeStatusUpdate, userJobType} from "@/api/user";
import {
  HRResumeStatusUpdateParams,
  HRJobResumeUpdate,
  HRJobResumeList,
  HRJobResumeListParams,
} from "@/api/user/company";
import SecondaryCategory from "../components/secondary-category.vue";


const PopupClose = 'https://yiliao.test03.qcw800.com/static/images/common/popup-close.png'
const options = ref<Record<string, string>>({});

interface MenuItem {
  type: string;
  name: string;
  showPopup: boolean;
}

const menu = ref<Array<MenuItem>>([
  {
    name: "全部职位",
    type: "1",
    showPopup: true,
  },
  {
    name: "待处理",
    type: "2",
    showPopup: true,
  },
  // {
  //   name: "时间段",
  //   type: "3",
  //   showPopup: true,
  // },
]);
// 职位分类列表
const classificationList = ref([]);
const getUserJobType = async () => {
  let res = await userJobType();
  if(res) {
    res.map(v => {
      if(v.pid === 0) {
        classificationList.value.push({
          name: v.content,
          code: v.id,
          children: []
        })
      }
    })
    res.map(v => {
      classificationList.value.map(item => {
        if(classificationList.value.filter(vx => vx.code === v.id)) {
          if(item.code === v.pid) {
            item.children.push({
              name: v.content,
              code: v.id
            })
          }
        }
      })
    })
  }
}
let statusList = ref([{
  name: '待处理',
  code: 1
}, {
  name: '已联系',
  code: 2
}, {
  name: '不合适',
  code: 3
},{
  name: '通过初筛',
  code: 4
}, {
  name: '通过初试',
  code: 5
}, {
  name: '通过复试',
  code: 6
}, {
  name: '通过终试',
  code: 7
}, {
  name: '已签约',
  code: 8
}])

const routerToResumeDetail = (resume_id: number) => {
  uni.navigateTo({
    url: '/pages/userinfo/resume-HRPerspective?resume_id='+resume_id,
  });
};


const secondaryCategoryList = ref<List>([]);
const popupData = reactive({
  show: false,
  title: "",
  menuType: "",
});
const showPopup = (item: MenuItem) => {
  console.log(item.type)
  if (item.showPopup) {
    popupData.title = item.name;
    popupData.menuType = item.type;
    popupData.show = true;
    if (item.type === "1") {
      secondaryCategoryList.value = classificationList.value;
    }
  }
};
const close = () => {};
const open = () => {};

async function onClickNoAgree(resume_id:number, index:number) {
  let params:HRResumeStatusUpdateParams = {
    job_resume_id: resume_id,
    status: 3,
  }
  console.log('不合适参数:::', params)
  let r = await HRJobResumeUpdate(params, '收到简历')
  if (r > 0) {
    res[index].status = 3
    res[index].status_name = '不合适'
    //刷新页面
  }
}

const res:any = reactive([]);

let paramsValue = reactive({
  position_id: '',
  status: ''
})
const getSearchList = (value) => {
  console.log('----+++====', value.value[1])
  paramsValue.position_id = value.value[1].code
  popupData.show = false
  getJobResumeList()
}

const getStatus = (item) => {
  console.log('=====', item)
  paramsValue.status = item.code
  popupData.show = false
  getJobResumeList()
}

async function getJobResumeList() {
  // let params:HRJobResumeListParams = {
  //   ...paramsValue
  // }
  let result = await HRJobResumeList(paramsValue);
  result.forEach(item => {
    res.push(item)
  })
}
onLoad((params: any) => {
  options.value = params;
  getJobResumeList()
  getUserJobType()
});
const jump = (u:string) => {
  uni.navigateTo({
    url: u,
  });
}
</script>

  <style scoped lang="scss"></style>
